#ifndef NSSHARE_UTILS_HANDLE_POOL_H_
#define NSSHARE_UTILS_HANDLE_POOL_H_

#include <stack>

namespace nsshare
{
namespace utils
{
template<typename HandleType, HandleType minimum>
class HandlePool
{
public:
    HandlePool()
        : minimum_(minimum)
    {
    }

    HandleType Get()
    {
        if(pool_.size() == 0)
            pool_.push(++minimum_);

        HandleType handle = pool_.top();
        pool_.pop();
        return handle;
    }

    void Put(HandleType handle)
    {
        pool_.push(handle);
    }

private:
    std::stack<HandleType> pool_;
    HandleType minimum_;
};

}
}

#endif